$.ajax({
	type:'get',
	url:'/comments/lasted',
	success:function(res){
		console.log(res);
		var tpl = ` 
			{{each data}}
			<li>
            <a href="javascript:;">
              <div class="avatar">
                <img src="{{$value.author.avatar}}" alt="">
              </div>
              <div class="txt">
                <p>
                  <span>{{$value.author.nickName}}</span>{{$value.createAt.split('T')[0]}}说:
                </p>
                <p>{{$value.content}}</p>
              </div>
            </a>
          </li>
          {{/each}}
		`
		var html = template.render(tpl,{data:res})
		$('.discuz').html(html)
	}
})

// 优雅：dont repeat yourself 不要重复你自己 提取到公共的地方


//实现左侧导航功能
$.ajax({
	type:'get',
	url:'/categories',
	success:function(res){
		console.log(res);
		var tpl = ` 
				{{each data}}
					<li><a href="list.html?categoryId={{$value._id}}"><i class="fa {{$value.className}}"></i>{{$value.title}}</a></li>
				{{/each}}
		`
		var html = template.render(tpl,{data:res})
		$('.header .nav').html(html)
	}
})


//实现搜索功能
// 1. 把list.html拷贝了一份，名字变成search.html 
// 2. 在public.js当中写了如下代码
$('.search form').on('submit',function(){
	var key = $(this).find('.keys').val()//搜索的关键字
	location.href = 'search.html?key='+key;
	return false;
})